
extern crate vulkano as vk;
extern crate winit;

use winit::{ dpi::PhysicalSize};
use winit::{
    event::{Event, WindowEvent},
    event_loop::{ControlFlow, EventLoop},
    window::WindowBuilder,
};

const WIDTH: u32 = 1024;
const HEIGHT: u32 = 768;


struct Application {
}

impl Application {
    pub fn new() -> Self {
        Self {
        }
    }

    pub fn run(&mut self) {
        let event_loop = EventLoop::new();
        let _window = WindowBuilder::new()
            .with_title("第00 base code")
            // .with_resizable(false) // false：窗口不可缩放
            .with_inner_size(PhysicalSize::new(WIDTH, HEIGHT))
            .build(&event_loop)
            .unwrap();

        event_loop.run(move |event, _, control_flow |{
            *control_flow = ControlFlow::Poll;
            *control_flow = ControlFlow::Wait;

            match event {
                Event::WindowEvent {
                    event: WindowEvent::CloseRequested,
                    ..
                } => {
                    println!("窗口关闭！");
                    *control_flow = ControlFlow::Exit;
                },
                Event::MainEventsCleared => {
                    // Application update code.

                    // Queue a RedrawRequested event.
                    //
                    // You only need to call this if you've determined that you need to redraw, in
                    // applications which do not always need to. Applications that redraw continuously
                    // can just render here instead.

                    _window.request_redraw();
                },
                Event::RedrawRequested(_) => {
                    // Redraw the application.
                    //
                    // It's preferable for applications that do not render continuously to render in
                    // this event rather than in MainEventsCleared, since rendering in here allows
                    // the program to gracefully handle redraws requested by the OS.
                },
                _ =>()
            }
        });
    }
}

fn main() {
    println!("00 —— base code");

    let mut app = Application::new();
    app.run();
}